/**
 * ConnectorLauncher.java
 * 9 mai 2010 01:37:54
 * Copyright Julien 2010
 */
package fr.jbrunet.win.ndriveconnector;

import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import fr.jbrunet.logger.JLog;
import fr.jbrunet.win.gui.ndriveconnector.NDriveConnector;

/**
 * @author Julien BRUNET
 *
 */
public class NDriveConnectorLauncher {

	private static final Logger log = JLog.getLogger(NDriveConnectorLauncher.class);

	public static void main (String [] args) {
		log.debug("Main program starts");

		try {
			
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			NDriveConnector window = new NDriveConnector(shell, SWT.NULL);

			Point size = window.getSize();
			shell.setLayout(new FillLayout());
			shell.layout();
			if(size.x == 0 && size.y == 0) {
				window.pack();
				shell.pack();
			} else {
				Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
				shell.setSize(shellBounds.width, shellBounds.height);
			}
			shell.open();

			//Then launch the connectionChecker
			//new ConnectionChecker(window.getShell()).start();

			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			NDriveConnector.quit();
		} catch (Exception e) {
			log.fatal(e);
		}
		finally {
			log.debug("Main program ends");
		}
	}
}

